import Vue from 'vue'
import VueRouter from 'vue-router'
import ManageMenuView from "@/views/manageviews/ManageMenuView";
import UserView from "@/views/manageviews/usermenu/UserView";
import UserListView from "@/views/manageviews/usermenu/user/UserListView";
import LoginView from "@/views/webviews/LoginView.vue";
import ManageLoginView from "@/views/manageviews/LoginView.vue"
import RegisterView from "@/views/webviews/RegisterView.vue";
import LobbyTypeView from "@/views/manageviews/lobbyTypeMenu/LobbyTypeView.vue";
import LobbyTypeListView from "@/views/manageviews/lobbyTypeMenu/lobbyType/LobbyTypeListView.vue";
import AddLobbyTypeView from "@/views/manageviews/lobbyTypeMenu/lobbyType/AddLobbyTypeView.vue";
import MovieTypeView from "@/views/manageviews/movieTypeMenu/MovieTypeView";
import MovieTypeListView from "@/views/manageviews/movieTypeMenu/movieType/MovieTypeListView";
import CinemaView from "@/views/manageviews/cinemaMenu/CinemaView.vue";
import CinemaListView from "@/views/manageviews/cinemaMenu/cinema/CinemaListView.vue";
import AddCinemaView from "@/views/manageviews/cinemaMenu/cinema/AddCinemaView.vue";
import MovieView from "@/views/manageviews/movieMenu/MovieView";
import MovieListView from "@/views/manageviews/movieMenu/Movie/MovieListView";
import MovieAddView from "@/views/manageviews/movieMenu/Movie/MovieAddView";
import ActorView from "@/views/manageviews/actorMenu/ActorView";
import ActorListView from "@/views/manageviews/actorMenu/actor/ActorListView";
import MovieAddActorView from "@/views/manageviews/movieMenu/Movie/MovieAddActorView";
import ScreeningView from "@/views/manageviews/ScreeningMenu/ScreeningView"
import ScreeningListView from "@/views/manageviews/ScreeningMenu/Screening/ScreeningListView";
import ScreeningAddView from "@/views/manageviews/ScreeningMenu/Screening/ScreeningAddView";
import BrandTypeView from "@/views/manageviews/brandTypeMenu/BrandTypeView";
import BrandTypeListView from "@/views/manageviews/brandTypeMenu/brandType/BrandTypeListView";
import OrdersView from "@/views/manageviews/orderMenu/OrdersView";
import OrdersListView from "@/views/manageviews/orderMenu/order/OrdersListView";
import OrdersDetailsListView from "@/views/manageviews/orderMenu/order/OrdersDetailsListView";
import lobbyView from "@/views/manageviews/lobbyMenu/LobbyView.vue";
import LobbyListView from "@/views/manageviews/lobbyMenu/lobby/LobbyListView.vue";
import AddLobbyView from "@/views/manageviews/lobbyMenu/lobby/AddLobbyView.vue";
import SeatMap from "@/views/manageviews/seatView/SeatMap.vue";
import FoodListView from "@/views/manageviews/foodMenu/food/FoodListView";
import FoodView from "@/views/manageviews/foodMenu/FoodView";
import ComboListView from "@/views/manageviews/foodMenu/Combo/ComboListView";
import FoodAddView from "@/views/manageviews/foodMenu/food/FoodAddView";
import ComboAddview from "@/views/manageviews/foodMenu/Combo/ComboAddview";
import BrandTypeAddView from "@/views/manageviews/brandTypeMenu/brandType/BrandTypeAddView";
import WebMenuView from "@/views/webviews/WebMenuView";
import CommentsView from "@/views/manageviews/commentsMenu/CommentsView";
import CommentsListView from "@/views/manageviews/commentsMenu/comments/CommentsListView";
import ReplyView from "@/views/manageviews/commentsMenu/comments/ReplyView";
import WebMovieView from "@/views/webviews/WebMovieView";
import index from "@/views/webviews/index"
import ShopView from "@/views/webviews/ShopView";
import SettlementView from "@/views/webviews/SettlementView";
import map from "@/views/webviews/map";
import WebMovieDetailPageView from "@/views/webviews/WebMovieDetailPageView";
import UserOrderView from "@/views/webviews/UserOrderView";
import UserMenuView from "@/views/webviews/UserMenuView";
import InformationView from "@/views/webviews/InformationView";
import UserOrderDetailsView from "@/views/webviews/UserOrderDetailsView";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: LoginView
  },
  {
    path: '/register',
    name: 'register',
    component: RegisterView
  },
  // {
  //   path: '/about',
  //   name: 'about',
  //   component: AboutView
  // },
  {
    path: '/login',
    name: 'manageLogin',
    component: ManageLoginView
  },
  {
    path: '/webMenu',
    name: 'webMenu',
    component: WebMenuView,
    children: [
      {
        path: '/index',
        name: 'index',
        component: index
      },
      {
        path: 'userOrderDetails',
        name: 'userOrderDetails',
        component: UserOrderDetailsView
      },
      {
        path: 'userMenu',
        name: 'userMenu',
        component: UserMenuView,
        children: [
          {
            path: 'userOrder',
            name: 'userOrder',
            component: UserOrderView
          },
          {
            path: 'information',
            name: 'information',
            component: InformationView
          }
        ]
      },
      {
        path: 'shop',
        name: 'shop',
        component: ShopView
      },
      {
        path:'settlement',
        name:'settlement',
        component: SettlementView
      },
      {
        path: "map",
        name: "map",
        component: map
      },
      {
        path: "WebMovieDetailPage",
        name: "WebMovieDetailPage",
        component: WebMovieDetailPageView
      },
      {
        path: "WebMovie",
        name: "WebMovie",
        component: WebMovieView
      },
      {
        path: "seat",
        name: "seat",
        component: SeatMap
      }
    ]
  },
  {
    path: '/menu',
    name: 'menu',
    component: ManageMenuView,
    beforeEnter:  (to, from, next) => {
       axios.get("/manage/isLogin").then(response => {
         if (response.data.code === 200) next()
         else next({name:"manageLogin"})
      }).catch(err =>{
        console.log("aaa"+err)
        next(false)
      })
    },
    children:[
      {
        path: "/movieType",
        name: "movieType",
        component: MovieTypeView,
        children: [
          {
            path: "list",
            name: "list",
            component: MovieTypeListView
          }
        ]
      },

      {
        path: "/movie",
        name: "movie",
        component: MovieView,
        children: [
          {
            path: "list",
            name: "list",
            component: MovieListView
          },
          {
            path: "add",
            name: "add",
            component: MovieAddView
          },
          {
            path: "addActor",
            name: "addActor",
            component: MovieAddActorView
          }
        ]
      },
      {
        path: "/brand",
        name: "brand",
        component: BrandTypeView,
        children: [
          {
            path: "list",
            name: "list",
            component: BrandTypeListView
          },
          {
            path: "add",
            name: "add",
            component: BrandTypeAddView
          },
        ]
      },
      {
        path: '/user',
        name: 'user',
        component: UserView,
        children:[
          {
            path: 'list',
            name: 'list',
            component: UserListView
          }
        ],
      },
      {
        path: '/comments',
        name: 'comments',
        component: CommentsView,
        children:[
          {
            path: 'list',
            name: 'list',
            component: CommentsListView
          },
          {
            path: 'reply',
            name: 'reply',
            component: ReplyView
            // children:[
            //   {
            //     path: 'list',
            //     name: 'list',
            //     component: CommentsListView
            // //   }
            // ],
          },
        ],
      },
      {
        path: '/lobby',
        name: 'lobby',
        component: lobbyView,
        children:[
          {
            path: 'list',
            name: 'lobbyList',
            component: LobbyListView
          },
          {
            path: 'add',
            name: 'addLobby',
            component: AddLobbyView
          }
        ]
      },
      {
        path: '/lobbyType',
        name: 'lobbyType',
        component: LobbyTypeView,
        children:[
          {
            path: 'list',
            name: 'lobbyTypeList',
            component: LobbyTypeListView
          },
          {
            path: 'add',
            name: 'addLobbyType',
            component: AddLobbyTypeView
          }
        ]
      },
      {
        path: "/actor",
        name: "actor",
        component: ActorView,
        children: [
          {
            path: "list",
            name: "list",
            component: ActorListView
          }
        ]
      },
      {
        path: '/cinema',
        name: 'cinema',
        component: CinemaView,
        children:[
          {
            path: 'list',
            name: 'cinemaList',
            component: CinemaListView
          },
          {
            path: 'add',
            name: 'addCinema',
            component: AddCinemaView
          },
        ]
      },
      {
        path: '/screening',
        name: 'screening',
        component: ScreeningView,
        children: [
          {
            path: 'list',
            name: 'list',
            component: ScreeningListView
          },
          {
            path: 'add',
            name: 'add',
            component: ScreeningAddView
          }
        ]
      },
      {
        path: '/orders',
        name: 'orders',
        component: OrdersView,
        children: [
          {
            path: 'list',
            name: 'list',
            component: OrdersListView
          },
          {
            path: 'ordersDetailsList',
            name: 'ordersDetailsList',
            component: OrdersDetailsListView
          }
        ]
      },
      {
        path: '/food',
        name: 'food',
        component: FoodView,
        children:[
          {
            path: 'list',
            name: 'foodlist',
            component: FoodListView,
          },
          {
            path: 'combo',
            name: 'combolist',
            component: ComboListView,
          },
          {
            path: 'add',
            name: 'addfood',
            component: FoodAddView,
          },
          {
            path: 'addcombo',
            name: 'addcombo',
            component: ComboAddview,
          }
        ]
      },
    ]
  },
  {
    path:'/seatView/:id/:col/:row',
    name:'seat',
    component:SeatMap,
    props:true
  }
]

const router = new VueRouter({
  routes
})

/**
 * 获取原型对象push函数
 */
const originalPush = VueRouter.prototype.push

/**
 * 获取原型对象replace函数
 */
const originalReplace = VueRouter.prototype.replace

/**
 * 修改原型对象中的push函数
 */
VueRouter.prototype.push = function push(location){
  return originalPush.call(this , location).catch(err => err)
}

/**
 * 修改原型对象中的replace函数
 */
VueRouter.prototype.replace = function replace(location){
  return originalReplace.call(this , location).catch(err => err)
}

export default router
